<?php

/**
 * Created by PhpStorm.
 * Script Name: EventAuthorizedHandler.php
 * Create: 2020/4/15 10:54
 * Description: 第三方公众号授权成功处理器
 * Author: fudaoji<fdj@kuryun.cn>
 */
namespace plugin\wechat\app\platform\handler\platform;

use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
use plugin\wechat\app\model\Mini;
use plugin\wechat\app\model\Mp;
use plugin\wechat\app\service\Mini as MiniService;
use plugin\wechat\app\service\Mp as MpService;


class EventUnAuthorizedHandler implements EventHandlerInterface
{

    /**
     * 取消授权处理器
     * @param mixed $payload
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author fudaoji<fdj@kuryun.cn>
     */
    public function handle($payload = null) {
        $appid = $payload['AuthorizerAppid'];
        if($mp = Mp::where('appid', $appid)->find()){
            MpService::cancelAuth($mp);
        }else{
            $mini = Mini::where('appid', $appid)->find();
            MiniService::cancelAuth($mini);
        }
    }
}